
#include "vector.h"

#include <attest/attest.h>

ATTEST(vector, init)
{
  pup_vector_t vector;
  ATTEST_EQ(0, pup_vector_init(&vector));
  ATTEST_EQ(NULL, vector.begin);
  ATTEST_EQ(NULL, vector.end);
  ATTEST_EQ(NULL, vector.alloc_end);
  ATTEST_EQ(NULL, pup_vector_begin_const(&vector));
  ATTEST_EQ(NULL, pup_vector_begin(&vector));
  ATTEST_EQ(NULL, pup_vector_end_const(&vector));
  ATTEST_EQ(NULL, pup_vector_end(&vector));
  ATTEST_EQ(0, pup_vector_capacity(&vector));
  ATTEST_TRUE(pup_vector_empty(&vector));
  ATTEST_EQ(0, pup_vector_size(&vector));
}

ATTEST(vector, uninit)
{
  pup_vector_t vector;
  ATTEST_EQ(0, pup_vector_init(&vector));
  ATTEST_EQ(0, pup_vector_uninit(&vector));
}

ATTEST(vector, empty)
{
  pup_vector_t vector;
  ATTEST_EQ(0, pup_vector_init(&vector));
  ATTEST_TRUE(pup_vector_empty(&vector));
}

ATTEST(vector, push_back)
{
  pup_item_t items[64];
  pup_vector_t vector;
  ATTEST_EQ(0, pup_vector_init(&vector));
  for(size_t i = 0; i != sizeof(items)/sizeof(pup_item_t); ++i) {
    items[i].szt = i;
    ATTEST_EQ(0, pup_vector_push_back(&vector, items[i]));
    ATTEST_FALSE(pup_vector_empty(&vector));
    ATTEST_EQ(i+1, pup_vector_size(&vector));
  }
}

